﻿using System;
using System.Collections.Generic;
using System.Text;
using PacMan3D.Utils;
using Tao.OpenGl;

namespace PacMan3D.Objects
{
    public class SkySphere : IRenderable
    {
        private int SkyTextureId;

        private RGBAColor BlendColor;

        public int Radius {get; private set;}

        private Point3D Position;
        private Glu.GLUquadric Quadric;

        public SkySphere(Point3D position, int radius)
        {
            this.Position = position;
            this.Radius = radius;

            this.BlendColor = new RGBAColor(StandardColors.White, 1.0f);

            this.Quadric = Glu.gluNewQuadric();
            Glu.gluQuadricTexture(this.Quadric, Gl.GL_TRUE); 
            Glu.gluQuadricDrawStyle(this.Quadric, Glu.GLU_FILL);
            Glu.gluQuadricNormals(this.Quadric, Glu.GLU_SMOOTH);
            this.SkyTextureId = ResourceLoader.LoadResource(Constants.RES_TEXT_SKY);
        }

        public override void DrawObject()
        {
            Gl.glDisable(Gl.GL_CULL_FACE);
            Gl.glPushMatrix();
                Gl.glEnable(Gl.GL_TEXTURE_2D);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, this.SkyTextureId);
                Gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f); 
                Gl.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
                Glu.gluSphere(this.Quadric, this.Radius, 30, 30);
                Gl.glDisable(Gl.GL_TEXTURE_2D);
            Gl.glPopMatrix();
            Gl.glEnable(Gl.GL_CULL_FACE);
        }
    }
}
